// 二分查找函数
int binary_search(int k,int* parr,int len)
{
	int left = 0;
	int right = len - 1;
	while (left <= right)
	{
		// int middle = (right + left) / 2;
		int middle = left + (right - left) / 2; // 防止溢出
		if (*(parr + middle) < k)
			left = middle + 1;
		else if (*(parr + middle) > k)
			right = middle - 1;
		else
			return middle;
	}
	return -1;
}
int main()
{
	// 实现整型有序数组的二分查找
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	int sz = sizeof arr / sizeof arr[0];
	// printf("%d\n", sz);
	int n = 11;
	int index = binary_search(n,arr,sz);
	if (index != -1)
		printf("找到了，下标是%d\n", index);
	else
		printf("没找到。\n");
	return 0;
}